import request from '@/utils/request'

export function getList(type, params) {
  let url = ''
  switch (type) {
    case 'getStatistics':
      url = 'getStatistics'
      break
    case 'getStatisticsLine':
      url = 'getStatisticsLine'
      break
    case 'getStatisticsBar':
      url = 'getStatisticsBar'
      break
    case 'getStatisticsPie':
      url = 'getStatisticsPie'
      break
    case 'getCreditStatistics':
      url = 'getCreditStatistics'
      break
    case 'getCreditStatisticsLine':
      url = 'getCreditStatisticsLine'
      break
    case 'getCreditStatisticsBar':
      url = 'getCreditStatisticsBar'
      break
    case 'getCreditStatisticsPie':
      url = 'getCreditStatisticsPie'
      break
    case 'getExceedStatistics':
      url = 'getExceedStatistics'
      break
    case 'getExceedStatisticsLine':
      url = 'getExceedStatisticsLine'
      break
    case 'getExceedStatisticsBar':
      url = 'getExceedStatisticsBar'
      break
    case 'getExceedStatisticsPie':
      url = 'getExceedStatisticsPie'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'get',
      params
    })
      .then(res => {
        resolve(res)
      })
      // eslint-disable-next-line handle-callback-err
      .catch(error => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve(data)
      })
  })
}

export function addOne(type, data) {
  let url = ''
  switch (type) {
    case '':
      url = ''
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function updateOne(type, data) {
  let url = ''
  switch (type) {
    case '':
      url = ''
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function deleteOne(type, data) {
  let url = ''
  switch (type) {
    case '':
      url = ''
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

